﻿using System;
using System.Threading.Tasks;

namespace Chapter1_12
{
    public static class Program
    {
        public static void Main(string[] args)
        {
            Task<int[]> parent = Task.Run(() => {
                var results = new int[3];

                new Task(() => results[0] = 0, TaskCreationOptions.AttachedToParent).Start();
                new Task(() => results[1] = 1, TaskCreationOptions.AttachedToParent).Start();
                new Task(() => results[2] = 2, TaskCreationOptions.AttachedToParent).Start();

                return results;
            });

            Task FinalTask = parent.ContinueWith((i) =>
                {
                    foreach (int item in i.Result)
                    {
                        Console.WriteLine("Task result {0}", item);
                    }
                });

            FinalTask.Wait();
            Console.ReadLine();
        }
    }
}
